package com.shad;

public class MyLinkedList implements MyList {
    private MyListItem head = new MyListItem();
    private MyListItem tail = new MyListItem();
    private int size;

    public MyLinkedList() {
        head.setNext(tail);
        tail.setPrevious(head);
    }

    @Override
    public void add(Object item) {
        MyListItem tmp = new MyListItem(item, null, tail);
        tail.next = tmp;
        size++;
    }

    @Override
    public void add(Object item, int toIndex) {
        if (toIndex < 0 || toIndex > size-1) {
            return;//TODO
        }
        size++;
    }

    @Override
    public void remove(Object item) {
        size--;
    }

    @Override
    public void clear() {
        size = 0;
    }

    public class MyListItem {
        private Object data;
        private MyListItem next;
        private MyListItem previous;

        public MyListItem() {

        }

        public MyListItem(Object data, MyListItem next, MyListItem previous) {
            this.data = data;
            this.next = next;
            this.previous = previous;
        }

        public Object getData() {
            return data;
        }

        public void setData(Object data) {
            this.data = data;
        }

        public MyListItem getNext() {
            return next;
        }

        public void setNext(MyListItem next) {
            this.next = next;
        }

        public MyListItem getPrevious() {
            return previous;
        }

        public void setPrevious(MyListItem previous) {
            this.previous = previous;
        }
    }
}